package com.pospi.xstore.http;


import android.content.Context;

import com.pospi.xstore.App;
import com.pospi.xstore.dao.OrderDao;
import com.pospi.xstore.dto.OrderBeen;
import com.pospi.xstore.dto.OrderDto;
import com.pospi.xstore.greendao.OrderBeenDao;
import com.pospi.xstore.util.GetData;

import java.util.List;


/**
 * Created by Qiyan on 2016/5/20.
 * <p>
 * 得到当前可以用的最大的订单号
 */
public class MaxNO {

    public static String getMaxNo(Context context) {
        OrderBeenDao dao = App.getInstance().getDaoSession().getOrderBeenDao();
        String maxNo = "";
        List<OrderBeen> orderDtos = dao.queryBuilder().where(OrderBeenDao.Properties.Time.eq(GetData.getYYMMDDTime())).list();

        if (orderDtos.size() == 0) {
            maxNo = GetData.getYYMMDDHHMMSSNoSpellingTime() + "0001";
        } else {
            String s = orderDtos.get(orderDtos.size() - 1).getMaxNo();
            int youNumber = Integer.parseInt(s.substring(s.length() - 4, s.length()))+1;
            String str = String.format("%04d", youNumber);
            maxNo = GetData.getYYMMDDHHMMSSNoSpellingTime() + str;
        }

        return maxNo;
    }
}